package cas;

import java.util.concurrent.atomic.AtomicInteger;

public class CasCount extends Thread {
    private AtomicInteger atomicInteger = new AtomicInteger(0);

    @Override
    public void run() {
        while (atomicInteger.get() <= 10000) {
            int i = atomicInteger.getAndIncrement();
            System.out.println(Thread.currentThread().getName() + "," + i);
        }
    }

    public static void main(String[] args) throws InterruptedException {
        long start = System.currentTimeMillis();
        CasCount cas1 = new CasCount();
        CasCount cas2 = new CasCount();
        cas1.start();
        cas2.start();
        cas1.join();
        cas2.join();
        long end = System.currentTimeMillis();
        System.out.println("共花费：" + (end - start));
    }
}
